package com.wkk.quartz.dto;

import cn.hutool.core.bean.BeanUtil;
import com.wkk.form.BaseDtoForm;
import com.wkk.quartz.entity.QuartzJob;
import com.wkk.verification.group.AddDto;
import com.wkk.verification.group.UpdateDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;

/**
 * @author : WangKeKe
 * @date : 2020/9/29 18:07
 * Description : 定时任务更新传输对象
 * - 做了分组校验
 */
@Data
@Accessors(chain = true)
@ApiModel(description = "定时任务更新传输对象")
@EqualsAndHashCode(callSuper = false)
public class QuartzAddOrUpdateDto extends BaseDtoForm<QuartzJob> {

    @Null(message = "添加定时任务不能传递ID值", groups = AddDto.class)
    @NotEmpty(message = "更新定时任务主键不能为空", groups = UpdateDto.class)
    @ApiModelProperty(value = "主键")
    private String id;

    @NotEmpty(message = "任务不能为空", groups = {AddDto.class, UpdateDto.class})
    @ApiModelProperty(value = "任务类相对路径")
    private String jobClassName;

    @NotEmpty(message = "任务执行条件不能为空", groups = {AddDto.class, UpdateDto.class})
    @ApiModelProperty(value = "cron表达式")
    private String cronExpression;

    @ApiModelProperty(value = "自定义参数")
    @Length(max = 100, message = "自定义参数数值长度不能大于100")
    private String parameter;

    @ApiModelProperty(value = "定时任务描述")
    @Length(max = 200, message = "任务描述字数过多，应小于200")
    private String description;

    @NotNull(message = "请选择定时任务的状态", groups = {AddDto.class, UpdateDto.class})
    @ApiModelProperty(value = "定时任务状态 0暂停 1启动")
    private Integer status;

    @Override
    public QuartzJob buildEntity() {
        QuartzJob quartzJob = new QuartzJob();
        BeanUtil.copyProperties(this, quartzJob);
        return quartzJob;
    }
}
